package cn.cdeden.knowledge.dubbo;

import cn.cdeden.common.core.utils.MapstructUtils;
import cn.cdeden.common.core.utils.page.TableDataInfo;
import cn.cdeden.knowledge.api.domain.RemoteResourceService;
import cn.cdeden.knowledge.api.domain.RemoteResourceTypeService;
import cn.cdeden.knowledge.api.domain.dto.RemoteResourceQueryParam;
import cn.cdeden.knowledge.api.domain.vo.RemoteResourceTypeVo;
import cn.cdeden.knowledge.api.domain.vo.RemoteResourceVo;
import cn.cdeden.knowledge.domain.SysResource;
import cn.cdeden.knowledge.domain.SysResourceType;
import cn.cdeden.knowledge.domain.dto.SysResourceDto;
import cn.cdeden.knowledge.domain.dto.SysResourceQueryParam;
import cn.cdeden.knowledge.service.SysResourceService;
import cn.cdeden.knowledge.service.SysResourceTypeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

@RequiredArgsConstructor
@Service
@DubboService
public class RemoteResourceTypeServiceImpl implements RemoteResourceTypeService {

    private final SysResourceTypeService sysResourceTypeService;


    @Override
    public List<RemoteResourceTypeVo> getAll() {
        return MapstructUtils.convert(sysResourceTypeService.list(),RemoteResourceTypeVo.class);
    }

    @Override
    public List<RemoteResourceTypeVo> getByName(RemoteResourceTypeVo sysResourceType) {
        List<SysResourceType> sysResourceTypeList = sysResourceTypeService.list(new QueryWrapper<SysResourceType>().eq("resource_type_name", sysResourceType.getResourceTypeName()));
        return MapstructUtils.convert(sysResourceTypeList,RemoteResourceTypeVo.class);
    }

    @Override
    public List<RemoteResourceTypeVo> getByNameAndId(RemoteResourceTypeVo sysResourceType) {
        List<SysResourceType> sysResourceTypeList = sysResourceTypeService.list(new QueryWrapper<SysResourceType>()
            .eq("resource_type_name", sysResourceType.getResourceTypeName())
            .ne("resource_id", sysResourceType.getResourceId()));
        return MapstructUtils.convert(sysResourceTypeList,RemoteResourceTypeVo.class);
    }

    @Override
    public boolean save(RemoteResourceTypeVo sysResourceType) {
        SysResourceType convert = MapstructUtils.convert(sysResourceType, SysResourceType.class);
        return sysResourceTypeService.save(convert);
    }

    @Override
    public RemoteResourceTypeVo getById(Integer id) {
        return MapstructUtils.convert(sysResourceTypeService.getById(id),RemoteResourceTypeVo.class);
    }

    @Override
    public boolean updateById(RemoteResourceTypeVo sysResourceType) {
        SysResourceType convert = MapstructUtils.convert(sysResourceType, SysResourceType.class);
        return sysResourceTypeService.updateById(convert);
    }

    @Override
    public boolean removeById(Integer resourceTypeId) {
        return sysResourceTypeService.removeById(resourceTypeId);
    }
}
